package net.wanho.controller;

import lombok.RequiredArgsConstructor;
import net.wanho.po.ProductType;
import net.wanho.service.ProductTypeService;
import net.wanho.vo.R;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/productCategory")
public class ProductTypeController {
    private final ProductTypeService productTypeService;
    @GetMapping("/product-category-tree")
    public R ProductCategoryTree(){
        List<ProductType> productTypeList = productTypeService.typeList();
        return R.success(productTypeList);
    }
    @GetMapping("/verify-type-code")
    public R verifyTypeCode(String typeCode){
        boolean b = productTypeService.verifyTypeCode(typeCode);
        if(b){
            return R.success(b);
        }
        else {
            return R.success(b);
        }
    }
    @PostMapping("/type-add")
    public R typeAdd(@RequestBody ProductType productType){
        productTypeService.save(productType);
        return R.success("分类添加成功!");
    }
    @GetMapping("/{id}")
    public R getById(@PathVariable Integer id){
        ProductType productType = productTypeService.getById(id);
        return R.success(productType);
    }
    @PutMapping("/type-update")
    public R typeUpdate(@RequestBody ProductType productType){
        productTypeService.updateById(productType);
        return R.success("修改成功!");
    }
    @DeleteMapping("/type-delete/{id}")
    public R typeDelete(@PathVariable Integer id){
        productTypeService.removeById(id);
        return R.success("删除成功!");
    }

}
